package com.web.dao;

import com.web.controller.web.WebSysLogController;
import com.web.entity.CompanyMarketDetail;

import static org.apache.ibatis.jdbc.SqlBuilder.*;

/**
 * @author FDjavaone
 */
public class CompanyMarketDetailSqlProvider {

    public String insertSelective(CompanyMarketDetail record) {
        BEGIN();
        INSERT_INTO("t_company_market_detail");
        
        if (record.getContent() != null) {
            VALUES("content", "#{content,jdbcType=VARCHAR}");
        }
        
        if (record.getDetail() != null) {
            VALUES("detail", "#{detail,jdbcType=VARCHAR}");
        }
        
        if (record.getFromNum() != null) {
            VALUES("from_num", "#{fromNum,jdbcType=VARCHAR}");
        }
        
        if (record.getName() != null) {
            VALUES("name", "#{name,jdbcType=VARCHAR}");
        }
        
        if (record.getDescription() != null) {
            VALUES("description", "#{description,jdbcType=VARCHAR}");
        }
        
        if (record.getBal() != null) {
            VALUES("bal", "#{bal,jdbcType=VARCHAR}");
        }
        
        if (record.getPhone() != null) {
            VALUES("phone", "#{phone,jdbcType=VARCHAR}");
        }
        
        if (record.getCreateTime() != null) {
            VALUES("create_time", "#{createTime,jdbcType=TIMESTAMP}");
        }
        
        if (record.getModifyTime() != null) {
            VALUES("modify_time", "#{modifyTime,jdbcType=TIMESTAMP}");
        }
        
        return SQL();
    }

    public String updateByPrimaryKeySelective(CompanyMarketDetail record) {
        BEGIN();
        UPDATE("t_company_market_detail");
        
        if (record.getContent() != null) {
            SET("content = #{content,jdbcType=VARCHAR}");
        }
        
        if (record.getDetail() != null) {
            SET("detail = #{detail,jdbcType=VARCHAR}");
        }
        
        if (record.getFromNum() != null) {
            SET("from_num = #{fromNum,jdbcType=VARCHAR}");
        }
        
        if (record.getName() != null) {
            SET("name = #{name,jdbcType=VARCHAR}");
        }
        
        if (record.getDescription() != null) {
            SET("description = #{description,jdbcType=VARCHAR}");
        }
        
        if (record.getBal() != null) {
            SET("bal = #{bal,jdbcType=VARCHAR}");
        }
        
        if (record.getPhone() != null) {
            SET("phone = #{phone,jdbcType=VARCHAR}");
        }
        
        if (record.getCreateTime() != null) {
            SET("create_time = #{createTime,jdbcType=TIMESTAMP}");
        }
        
        if (record.getModifyTime() != null) {
            SET("modify_time = #{modifyTime,jdbcType=TIMESTAMP}");
        }
        
        WHERE("id = #{id,jdbcType=BIGINT}");
        
        return SQL();
    }

    public String selectRecord() {

        BEGIN();
        SELECT("id");
        SELECT("content");
        SELECT("detail");
        SELECT("content");
        SELECT("from_num");
        SELECT("bal");
        SELECT("description");
        SELECT("phone");
        SELECT("name");
        SELECT("create_time");
        SELECT("modify_time");
        FROM("t_company_market_detail");
        ORDER_BY("create_time desc");
        return SQL();
    }


    public String selectAllCompanyMarketLogs(WebSysLogController.DetailsColumns record) {
        BEGIN();
        SELECT("id");
        SELECT("content");
        SELECT("detail");
        SELECT("content");
        SELECT("from_num");
        SELECT("bal");
        SELECT("description");
        SELECT("phone");
        SELECT("name");
        SELECT("create_time");
        SELECT("modify_time");
        FROM("t_company_market_detail");
        if (record.getName() != null && !"".equals(record.getName())) {
            WHERE("name like #{name,jdbcType=VARCHAR}");
        }
        if (record.getPhone() != null && !"".equals(record.getPhone())) {
            WHERE("phone like #{phone,jdbcType=VARCHAR}");
        }

        if (record.getFromNum() != null && !"".equals(record.getFromNum())) {
            WHERE("from_num like #{fromNum,jdbcType=VARCHAR}");
        }

        if(record.getBegin_createTime()!=null){
            WHERE("create_time >= #{begin_createTime,jdbcType=TIMESTAMP}");
        }
        if(record.getEnd_createTime()!=null){
            WHERE("create_time <= #{end_createTime,jdbcType=TIMESTAMP}");
        }

        ORDER_BY("create_time desc");

        return SQL();
    }
}